"""
ros2 launch map_manager load_2d_map.launch.py map_file_path:=maps/6.10lab_mapping/2d_lab_map_-1587_-1537.png
dd
"""

from launch import LaunchDescription
from launch.actions import DeclareLaunchArgument, ExecuteProcess
from launch.substitutions import LaunchConfiguration
from launch_ros.actions import Node
from launch.conditions import IfCondition

def generate_launch_description():
    map_publish_times = LaunchConfiguration('map_publish_times')
    header_frame_id = LaunchConfiguration('header_frame_id')
    resolution = LaunchConfiguration('resolution')
    map_file_path = LaunchConfiguration('map_file_path')
    display_rviz = LaunchConfiguration('display_rviz')

    params = {
        "map_publish_times": map_publish_times,
        'header_frame_id': header_frame_id,
        "map_file_path": map_file_path,
        "resolution": resolution,
    }

    return LaunchDescription([
        DeclareLaunchArgument(
            'map_publish_times',
            default_value='2',
            description='Number of times to publish the map'
        ),
        DeclareLaunchArgument(
            'header_frame_id',
            default_value='map',
            description='Frame ID for the map header'
        ),
        DeclareLaunchArgument(
            'map_file_path',
            description='Path to the 2d map PNG file'
        ),
        DeclareLaunchArgument(
            'resolution',
            default_value='0.1',
            description='Resolution of the 2D map in meters per pixel'
        ),
        DeclareLaunchArgument(
            'display_rviz',
            default_value='true',
            description='Whether to display the map in RViz'
        ),
        ExecuteProcess(
            cmd=[
                'rviz2',
                '-d', 'src/map_manager/config/2d_map.rviz'
            ],
            output='screen',
            condition=IfCondition(display_rviz)
        ),
        Node(
            package='map_manager',
            executable='load_2d_map',
            name='load_2d_map_node',
            output='screen',
            parameters=[params]
        )
    ])